﻿using FrameWork.Data.DbData;
using FrameWork.Data.Enum;
using FrameWork.Data.Impl;
using FrameWork.Services;
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;

namespace AncheStart.Converter
{
    public class VariableInfoConverter : IValueConverter
    {
        public object Convert(object stepIndex, Type targetType, object parameter, CultureInfo culture)
        {
            InitData();
            var columnCode = (string)parameter;
            var variableInfo = GlobalConstant.ColumnInfos.Where(p => !string.IsNullOrEmpty(p.ColumnCode) && p.ColumnCode.Equals(parameter)).FirstOrDefault();
            return variableInfo == null ? 1 : variableInfo.Order;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
        private void InitData()
        {
            if (null == GlobalConstant.ColumnInfos)
            {
                var columnInfoManager = new ColumnInfoManager(new AppDbContext());
                GlobalConstant.ColumnInfos = columnInfoManager.queryByGridType(EnumGridType.Technology);
            }
            if (null == GlobalConstant.SegmentInfos)
            {
                var segmentInfoManager = new SegmentInfoManager(new AppDbContext()); //m_Container.Resolve<ISegmentInfoManager>();
                GlobalConstant.SegmentInfos = segmentInfoManager.getAll().Result;
            }
        }
    }
}